<?php
@session_start();
unset($_SESSION['message']);
unset($_SESSION['file_ready']);
$filePath = '../../uploadedFile/';

if (($_FILES["file"]["type"] == "application/vnd.ms-excel") && 
     ($_FILES["file"]["size"] < 1000000)) {
    
    if ($_FILES["file"]["error"] > 0) {
        $_SESSION['message'] = 'Error: '.$_FILES["file"]["error"];
    } else {
        
//        echo "Upload: " . $_FILES["file"]["name"] . "<br>";
//        echo "Type: " . $_FILES["file"]["type"] . "<br>";
//        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
//        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

        if (file_exists($filePath . $_FILES["file"]["name"])) {
            $_SESSION['message'] = 'Error: '.$_FILES["file"]["name"].' already exists!';
        } else {
            move_uploaded_file($_FILES["file"]["tmp_name"], $filePath . $_FILES["file"]["name"]);
            $_SESSION['file_ready'] = '1';
            $_SESSION['file_name'] = $_FILES["file"]["name"];
            $_SESSION['file_path'] = $filePath;
        }
    }
    
} else {
    $_SESSION['message'] = 'Bukan File CSV';
}
header("location: ../uploadFile1.php");

?>
